int i, n; //make some ints
char * buffer; //make a character buffer

printf ("How long do you want the string? "); //ask the user a question about string length
scanf("%d", &i); //read in what they typed

buffer = (char*) malloc (i+1); //put what they've typed into the buffer

if (buffer == NULL) 
exit (1); //These two lines quit the program if there's nothing in the buffer. Not ideal really.
//it'd be better if there was a printf("No data in text buffer. Program will now exit");

for (n=0; n<i; n++) {
buffer[n] = rand() % 26 +'a'; //Make a mess
}
buffer[i]='\0';

printf ("Random string: %s\n",buffer); //regurgitate the string we made at random back to the user

free (buffer); //clean up the mess in the buffer
//no sign of the exit line at the end there. Also, there's no main method. This code would never compile on its own.
